import org.cscarioni.Backlog 
import org.cscarioni.User;
import org.cscarioni.Card 
import org.cscarioni.Team;
import org.cscarioni.Panel;
import org.cscarioni.Project 
import org.cscarioni.Sprint 
import org.cscarioni.Story 
import org.cscarioni.Role
import org.cscarioni.UserPreferences
import org.cscarioni.Requestmap



class BootStrap {
	 def projectService
	 def authenticateService
     def init = { servletContext ->
		println "INITIALIZING"
		def pass=authenticateService.passwordEncoder("cscrum").toString()		
		def project = new Project(name:'Portae',description:'Proyecto portae')
		project.backlog=new Backlog()
		def story=new Story(name:'Story 1',description:'Alta Anuncio')
		project.backlog.addToStories(story)
		projectService.save(project)		
		def roleUser = new Role(description:'Usuario normal',authority:'ROLE_USER')
		roleUser.save()
		def roleAdmin = new Role(description:'Usuario administrador',authority:'ROLE_ADMINISTRATOR')
		roleAdmin.save()
		def roleScrumMaster = new Role(description:'Usuario Scrum Master',authority:'ROLE_SCRUMMASTER')
		roleScrumMaster.save()
		def carlo=new User(username: 'Carlo',userRealName:'Carlo',passwd:pass,email:'cscarioni@paradigmatecnologico.com',enabled:true)
		carlo.addToAuthorities(roleAdmin)
		carlo.addToAuthorities(roleScrumMaster)
		roleAdmin.addToPeople(carlo)
		roleScrumMaster.addToPeople(carlo)
		carlo.addToAuthorities(roleUser)
		roleUser.addToPeople(carlo)
		def pablo = new User(username: 'Pablo',userRealName:'Pablo',passwd:pass,email:'ppazos@paradigmatecnologico.com',enabled:true)
		pablo.addToAuthorities(roleUser)
		roleUser.addToPeople(pablo)
		def team = new Team(name: 'Bocachanclas',users:[carlo,pablo])
		carlo.team=team
		pablo.team=team
		team.save()
		UserPreferences carloPreferences = new UserPreferences()
		new Requestmap(url:"/project/**",configAttribute:"IS_AUTHENTICATED_REMEMBERED").save()
		new Requestmap(url:"/card/**",configAttribute:"IS_AUTHENTICATED_REMEMBERED").save()
		new Requestmap(url:"/panel/**",configAttribute:"IS_AUTHENTICATED_REMEMBERED").save()
		new Requestmap(url:"/sprint/**",configAttribute:"IS_AUTHENTICATED_REMEMBERED").save()
		new Requestmap(url:"/story/**",configAttribute:"IS_AUTHENTICATED_REMEMBERED").save()
		new Requestmap(url:"/chart/**",configAttribute:"IS_AUTHENTICATED_REMEMBERED").save()
		
		println "SAVED"
     }
     def destroy = {
     }
} 